package edu.hubu.supermarketmanagementsystem.controller;

import edu.hubu.supermarketmanagementsystem.entity.Area;
import edu.hubu.supermarketmanagementsystem.service.AreaService;
import edu.hubu.supermarketmanagementsystem.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin  // 允许跨域请求 设置基本的 URL 路径
public class AreaController {

    // 注入 AreaService 服务
    @Autowired
    private AreaService areaService;


    // 添加区域
    @RequestMapping("/area/add")
    public ResultVO<Boolean> addArea(String name, String status, String location, Integer adminId) {
        return areaService.addArea(name, status, location, adminId);
    }

    @RequestMapping("/area/list")
    public ResultVO<List<Area>> listArea() {
        return areaService.getAreasList();
    }

    @RequestMapping("/area/update")
    public ResultVO<Boolean> updateArea(Integer id, String name, String status, String location, Integer adminId) {
        return areaService.updateArea(id, name, status, location, adminId);
    }

    @RequestMapping("/area/delete")
    public ResultVO<Boolean> deleteArea(Integer id) {
        return areaService.deleteArea(id);
    }
}
